package com.gen.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.gen.service.IGoodsService;
import com.gen.service.IKindsService;
import com.zzx.entity.Goods;

@Controller
public class GoodsController {
	@Autowired
	private IGoodsService goodsService;
	private IKindsService kindsService;

	public IGoodsService getGoodsService() {
		return goodsService;
	}

	public void setGoodsService(IGoodsService goodsService) {
		this.goodsService = goodsService;
	}
	
	@RequestMapping("/goodsList.do")
	public ModelAndView goodsList() {
		ModelAndView modelAndView = new ModelAndView();
		
		List<Object> kids = null;
		Map<String, Integer> goodsCountsByKid = goodsService.selectGoodsCountsByKid(kids);
//		System.out.println(goodsCountsByKid);
		modelAndView.setViewName("goodsList");
		modelAndView.addObject("goodsCountsByKid", goodsCountsByKid);
		return modelAndView;
	}
//	只看一种商品类型的
	@RequestMapping("/goodsListByKid.do")
	public ModelAndView goodsListByKid(@Param("kid") Integer kid) {
		ModelAndView modelAndView = new ModelAndView();
		List<Object> kids = new ArrayList<Object>();
		kids.add(kid);
		Map<String, Integer> goodsCountsByKid = goodsService.selectGoodsCountsByKid(kids);
		modelAndView.setViewName("goodsListByKid");
		modelAndView.addObject("goodsCountsByKid", goodsCountsByKid);
		return modelAndView;
	}
	
//	获得每个kid对应的商品所有信息
	@RequestMapping("/selectGoodsByParamContainsKid.do")
	@ResponseBody
	@CrossOrigin
	public Object selectGoodsByParamContainsKid(@Param("kid") Integer kid) {
		Goods goods = new Goods();
		goods.setKid(kid);
		List<Goods> selectGoodsByKid = goodsService.selectGoodsByParam(goods);
		return selectGoodsByKid;
	}
	
}
